<?php
if (!defined ('TYPO3_MODE')) {
	die ('Access denied.');
}

/**
 * @param array $params
 * @param object $parentObj
 */
function tx_filelinks_labelUserFunc($params, $parentObj)
{
    $title = '';
    $row = $params['row'];
    switch($row['link_type']) {
        case 1:
            $title = $row['link_page'];
            break;
        case 2:
            $title = $row['link_file'];
            break;
        case 3:
            $title = $row['link_url'];
            break;
        case 4:
            $title = $row['link_mail'];
            break;
    }
    $params['title'] = $title;
}


t3lib_extMgm::allowTableOnStandardPages('tx_filelinks');

$TCA['tx_filelinks'] = array (
	'ctrl' => array (
		'title'     => 'LLL:EXT:filelinks/locallang_db.xml:tt_content.tx_filelinks',
		'label'     => 'label',
        'label_alt' => 'link_page,link_file,link_url,link_mail', // required by label_userFunc?
        'label_userFunc' => 'tx_filelinks_labelUserFunc',
		'tstamp'    => 'tstamp',
		'crdate'    => 'crdate',
		'cruser_id' => 'cruser_id',
		'sortby' => 'sorting',	
		//'default_sortby' => 'ORDER BY crdate',
		'delete' => 'deleted',
		'enablecolumns' => array (
			'disabled' => 'hidden',
		),
		'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
		'iconfile'          => t3lib_extMgm::extRelPath($_EXTKEY).'ext_icon.gif',
	),
);

t3lib_div::loadTCA('tt_content');
$TCA['tt_content']['types'][$_EXTKEY . '_pi1']['showitem'] = 'CType;;4;button;1-1-1, header;;3;;2-2-2';


t3lib_extMgm::addPlugin(array(
	'LLL:EXT:filelinks/locallang_db.xml:tt_content.CType_pi1',
	$_EXTKEY . '_pi1',
	t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif'
),'CType');

$tempColumns = array (
	'tx_filelinks' => array (
		'exclude' => 0,
		'label' => 'LLL:EXT:filelinks/locallang_db.xml:tt_content.tx_filelinks',
		'config' => array (
			'type' => 'inline',
            'foreign_table' => 'tx_filelinks',
            'foreign_field' => 'parentid',
            'foreign_table_field' => 'parenttable',
            'maxitems' => 100,
		)
	),
);


t3lib_div::loadTCA('tt_content');
t3lib_extMgm::addTCAcolumns('tt_content',$tempColumns,1);

$TCA['tt_content']['types'][$_EXTKEY . '_pi1']['showitem'] = 'CType;;4;;1-1-1, hidden, header;;3;;2-2-2, linkToTop;;;;4-4-4, --div--;LLL:EXT:filelinks/locallang_db.xml:tt_content.CType_pi1, layout;;;;3-3-3, tx_filelinks, --div--;LLL:EXT:cms/locallang_tca.xml:pages.tabs.access, starttime, endtime, fe_group';

t3lib_extMgm::addLLrefForTCAdescr('tt_content','EXT:filelinks/locallang_csh.xml');

// CType Hook
if(is_file(t3lib_extMgm::extPath('cms').'layout/interfaces/interface.tx_cms_layout_tt_content_drawitemhook.php')) {
    require_once(t3lib_extMgm::extPath('filelinks').'class.tx_filelinks_drawItemHook.php');
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][] = 'tx_filelinks_drawItemHook';
}

?>